<script>
	
	import {
		getUserInfo
	} from './api/user';
	import Vue from 'vue';
	import {
		mapGetters
	} from "vuex";
	import Auth from '@/libs/wechat.js';
	// 主题样式配置
	let theme =
		'--view-theme: #FCFCE3;--view-btn:#FFCB05;--view-priceColor:#ED3E3E;--view-card-linear:linear-gradient(270deg, #1677FF 0%, #1677FF 100%);';
	export default {
		computed: mapGetters(['isLogin']),
		onLaunch: function() {
			// this.barHeight()
			// #ifdef MP-WEIXIN
			this.updateMp()
			// #endif
			// #ifdef H5
			// 设置config  jssdk（需要调试）
			// Auth.wechat()
			// #endif
			uni.setStorageSync('viewColor', theme)
			uni.$emit('ok', theme)
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			updateMp() {
				const updateManager = wx.getUpdateManager();
				const startParamObj = wx.getEnterOptionsSync();
				if (wx.canIUse('getUpdateManager') && startParamObj.scene != 1154) {
					const updateManager = wx.getUpdateManager()
					updateManager.onCheckForUpdate(function(res) {
						// 请求完新版本信息的回调
						if (res.hasUpdate) {
							updateManager.onUpdateFailed(function() {
								uni.$u.toast('新版本下载失败')
							});
							updateManager.onUpdateReady(function() {
								wx.showModal({
									title: '更新提示',
									content: '新版本已经下载好，是否重启当前应用？',
									success(res) {
										if (res.confirm) {
											updateManager.applyUpdate()
										}
									}
								})
							})
							updateManager.onUpdateFailed(function() {
								wx.showModal({
									title: '发现新版本',
									content: '请删除当前小程序，重启搜索打开...',
								})
							})
						}
					})
				}

			},
			
			barHeight() {
				uni.getSystemInfo({
					success: (e) => {
						// this.compareVersion(e.SDKVersion, '2.5.0')
						let statusBar = 0 //状态栏高度
						let customBar = 0 // 状态栏高度 + 导航栏高度  
						let navbar = 0 // 自定义标题与胶囊对齐高度


						// #ifdef MP
						statusBar = e.statusBarHeight
						customBar = e.statusBarHeight + 45
						if (e.platform === 'android') {
							this.$store.commit('SET_SYSTEM_IOSANDROID', false)
							customBar = e.statusBarHeight + 50
						}
						// #endif


						// #ifdef MP-WEIXIN
						statusBar = e.statusBarHeight
						const custom = wx.getMenuButtonBoundingClientRect()
						customBar = custom.bottom + custom.top - e.statusBarHeight

						navbar = (custom.top - e.statusBarHeight) * 2 + custom.height
						// #endif


						// #ifdef MP-ALIPAY
						statusBar = e.statusBarHeight
						customBar = e.statusBarHeight + e.titleBarHeight
						// #endif


						// #ifdef APP-PLUS
						statusBar = e.statusBarHeight
						customBar = e.statusBarHeight + 45
						// #endif


						// #ifdef H5
						statusBar = 0
						customBar = e.statusBarHeight + 45
						// #endif
						Vue.prototype.StatusBar = customBar;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
	@import 'static/css/global.scss';

	//全局背景颜色
	page {
		background: #F6F6F6;
	}

	.loading_box {
		text-align: center;
		font-size: 28rpx;
		color: #808080;
	}

	// 自定义tabBar，底部占位符
	.tabBar_bottom {
		width: 100%;
		padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
		padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
		height: 180rpx;
	}
</style>